﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="InlineComplexType", Namespace="http://kis.x-road.eu/", Target=typeof(InlineComplexType))]
    public class InlineComplexTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected InlineComplexType clazz;
        
        public InlineComplexTypeSerializer(InlineComplexType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Department");
            if (clazz.Department!=null) {
                global::Xtee.Core.SerializationMetadata metaDepartment = this.GetMetaData(clazz.Department);
                if (ShouldWriteTypeAttribute(typeof(InlineComplexType.DepartmentType), clazz.Department.GetType())) {
                    Writer.WriteTypeAttribute(metaDepartment.TypeQualifiedName.Namespace, metaDepartment.TypeQualifiedName.Name);
                }
                var departmentSerializer = metaDepartment.NewSerializer(clazz.Department);
                departmentSerializer.WriteXmlAttributes(Writer);
                departmentSerializer.WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Department");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Department") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>InlineComplexType>Department");
                }
                global::Xtee.Core.SerializationMetadata metaDepartment = this.GetMetaData<InlineComplexType.DepartmentType>(Reader, ">>InlineComplexType>Department", "http://kis.x-road.eu/");
                clazz.Department = metaDepartment.NewEntity<InlineComplexType.DepartmentType>();
                if ((Reader.IsEmptyElement == false)) {
                    var departmentSerializer = metaDepartment.NewSerializer(clazz.Department);
                    departmentSerializer.ReadXmlAttributes(Reader);
                    Reader.ReadStartElement("Department");
                    departmentSerializer.ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>InlineComplexType>Department", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>InlineComplexType>Department", Namespace="http://kis.x-road.eu/", Target=typeof(InlineComplexType.DepartmentType))]
        public class DepartmentTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected InlineComplexType.DepartmentType clazz;
            
            public DepartmentTypeSerializer(InlineComplexType.DepartmentType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXmlAttributes(Writer);
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Country");
                if (clazz.Country!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Country))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Country");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Floor");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Floor))).ToString());
                Writer.WriteEndElement();
            }
            
            public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXmlAttributes(Reader);
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Country") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>InlineComplexType>Department>Country");
                    }
                    clazz.Country = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Country")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>InlineComplexType>Department>Country", Reader.LocalName);
                }
                if (Reader.LocalName=="Floor") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>InlineComplexType>Department>Floor");
                    }
                    clazz.Floor = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("Floor")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>InlineComplexType>Department>Floor", Reader.LocalName);
                }
            }
        }
    }
}
